
#ifndef __NEW_ACTORS_DB_H
#define __NEW_ACTORS_DB_H

#include <apr-1/apr_network_io.h>
#include "../aprtools/APRTable.h"
#include "SQLiteDB.h"

class NewActorsDB : public SQLiteDB
{
   public:
      NewActorsDB(const char *filename);
      int addUser(const char *ihandlename,
                  const char *iname,
                  const char *iparent,
                  int64_t credit,
                  int64_t quota,
                  int64_t lifetime);
      int makeUserPermanent(const char *iname);
      int addCompute(const char *iname,
                     const char *iparent,
                     int64_t durationseconds,
                     apr_sockaddr_t *cliaddr,
                     const char *capabilities,
                     const char *joblocation);
      int spawnWorkInstances(const char *iinputworkstore,
                             int64_t durationseconds,
                             int iinstances);
      int addDataStore(const char *iname,
                       const char *iparent,
                       const char *iorigin,
                       const char *iallhash,
                       int noofblocks, int64_t blocksize);
      int addDependencyOnKey(const char *iname, const char *ikeyname);
      APRTable *getActor(const char *iname);
      int removeActor(const char *iname);
   private:
      static const char *table_actors_fields_names[];
      static const char *table_actors_fields_types[];
      static const char *table_users_fields_names[];
      static const char *table_users_fields_types[];
      static const char *table_computes_fields_names[];
      static const char *table_computes_fields_types[];
      static const char *table_workinstances_fields_names[];
      static const char *table_workinstances_fields_types[];
      static const char *table_datastores_fields_names[];
      static const char *table_datastores_fields_types[];
      static const char *table_keydependencies_fields_names[];
      static const char *table_keydependencies_fields_types[];
      char *makeFieldDefinitions(const char **dnames, const char **dtypes);
      char *makeCommaSeparatedList(const char **names);
      void createTablesIfNecessary();
      int addActor_unsafe(const char *iname,
                          const char *iclass,
                          const char *iparent,
                          const char *ivalidfrom,
                          const char *iexpireson,
                          const char *iactormark,
                          const char *iexternalalias);
      int getParent_unsafe(char **parent, const char *iname);
      
};

#endif
